This section is applicable to codec component developers.
Audio atoms are aways in big endian format. The atoms contained in this list can be in any order, ending with the AudioTerminatorAtom. No assumptions should be made about reading an audio atom list, other than the last atom is the AudioTerminatorAtom. Using the SndGetInfo function and the siDecompressionParams selector will return a list of atoms of any possible ordering, as shown in Listing 11 .
Listing 11 A list of audio atoms of any possible ordering
OSErr CreateAudioAtomsList(OSType format, Boolean littleEndian,
void **littleEndianAtomsList)
{
typedef struct {
AudioFormatAtom formatData;
AudioEndianAtom endianData;
AudioTerminatorAtom terminatorData;
} AudioDecompressionAtoms, *AudioDecompressionAtomsPtr;
atoms = (AudioDecompressionAtomsPtr)NewPtr(sizeof(AudioDecompressionAtoms));
if (atoms == nil)
return (MemError());
atoms->formatData.size = EndianU32_NtoB(sizeof(AudioFormatAtom));
atoms->formatData.atomType = EndianU32_NtoB(kAudioFormatAtomType);
atoms->formatData.format = EndianU32_NtoB(format);
atoms->endianData.size = EndianU32_NtoB(sizeof(AudioEndianAtom));
atoms->endianData.atomType = EndianU32_NtoB(kAudioEndianAtomType);
atoms->endianData.littleEndian = EndianU16_NtoB(littleEndian);
atoms->terminatorData.size = EndianU32_NtoB(sizeof(AudioTerminatorAtom));
atoms->terminatorData.atomType = EndianU32_NtoB(kAudioTerminatorAtomType);
*littleEndianAtomsList = atoms;
return (noErr);
}
Listing 12 How to read a list of audio atoms
Boolean GetFormatAndEndianFromAtomsList(UserDataAtom *atom, OSType
*format, Boolean *littleEndian)
{
Boolean moreAtoms;
moreAtoms = true;
do
{
if (EndianS32_BtoN(atom->size) < 8)
return (false);// bad atom size
switch (EndianU32_BtoN(atom->atomType))
{
case kAudioFormatAtomType:
*format = EndianU32_BtoN(((AudioFormatAtom *)atom)->format);
break;
case kAudioEndianAtomType:
*littleEndian = EndianU16_BtoN(((AudioEndianAtom
*)atom)->littleEndian);
break;
case kAudioTerminatorAtomType:
moreAtoms = false;
break;
default: // unknown atom type
break;
}
atom = (UserDataAtom *)((long)atom + EndianS32_BtoN(atom->size));
} while (moreAtoms);
}
| Previous | Chapter Contents | Chapter Top | Next |